package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.events.convert.UserUnlockSiteConvert;
import net.maku.events.entity.UserUnlockSiteEntity;
import net.maku.events.service.UserUnlockSiteService;
import net.maku.events.query.UserUnlockSiteQuery;
import net.maku.events.vo.UserUnlockSiteVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 用户解锁站点
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-22
*/
@RestController
@RequestMapping("events/user_unlock_site")
@Tag(name="用户解锁站点")
@AllArgsConstructor
public class UserUnlockSiteController {
    private final UserUnlockSiteService userUnlockSiteService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('events:user_unlock_site:page')")
    public Result<PageResult<UserUnlockSiteVO>> page(@ParameterObject @Valid UserUnlockSiteQuery query){
        PageResult<UserUnlockSiteVO> page = userUnlockSiteService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('events:user_unlock_site:info')")
    public Result<UserUnlockSiteVO> get(@PathVariable("id") Long id){
        UserUnlockSiteEntity entity = userUnlockSiteService.getById(id);

        return Result.ok(UserUnlockSiteConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('events:user_unlock_site:save')")
    public Result<String> save(@RequestBody UserUnlockSiteVO vo){
        userUnlockSiteService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('events:user_unlock_site:update')")
    public Result<String> update(@RequestBody @Valid UserUnlockSiteVO vo){
        userUnlockSiteService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('events:user_unlock_site:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        userUnlockSiteService.delete(idList);

        return Result.ok();
    }
}